﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web;
using System.Windows.Forms;

namespace JCore.LoLChat
{
    public partial class frmUserList : Form
    {
        public readonly static string key = "pGoKJiZ9YFfZO9EzYYiY";

        public frmUserList()
        {
            InitializeComponent();
        }

        private readonly Login login = new Login();

        private void frmUserList_Load(object sender, EventArgs e)
        {
            login.Connect("jipjan", "jaapjan95", this);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            


            lstUsers.Items.Clear();

            for (int j = 0; j < login.Friends.Count; j++)
            {
                ListViewItem temp = new ListViewItem();
                int index = -1;
                foreach (FriendsInfo friend in login.FriendsInfo)
                {
                    if (friend.PvpNetID == login.Friends[j].PvpNetID)
                    {
                        index = login.FriendsInfo.IndexOf(friend);
                        break;
                    }
                }
                if (index != -1)
                {
                    temp.Text = login.FriendsInfo[index].profileIcon.ToString(CultureInfo.InvariantCulture);
                    temp.SubItems.Add(login.Friends[j].SummonerName);
                    temp.SubItems.Add(login.FriendsInfo[index].gameStatus);
                    temp.SubItems.Add(HttpUtility.HtmlDecode(login.FriendsInfo[index].statusMsg));
                    lstUsers.Items.Add(temp);
                    lstUsers.Items[lstUsers.Items.Count - 1].Group = lstUsers.Groups[0];
                }
                else
                {
                    temp.SubItems.Add(login.Friends[j].SummonerName);
                    temp.SubItems.Add("Offline");
                    lstUsers.Items.Add(temp);
                    lstUsers.Items[lstUsers.Items.Count - 1].Group = lstUsers.Groups[1];
                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label1.Text = login.Friends.Count.ToString(CultureInfo.InvariantCulture);
            label2.Text = login.FriendsInfo.Count.ToString(CultureInfo.InvariantCulture);
        }

        private void lstUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lstUsers.SelectedIndices.Count != 0)
            {
                lblSumName.Text = "Summoner Name: " + lstUsers.SelectedItems[0].SubItems[1].Text;
            }
        }

        /*
        public void AddUserToFlowLayout(string SummName)
        {
            Label summoner = new Label();
            summoner.Name = SummName;
            summoner.Text = SummName;
            flwChatScreens.Controls.Add(summoner);
        }
         * */
    }
}
